import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class THI extends Thread {

    private Robot robot;
    public static boolean b = true;
    Integer i;
    Integer w;
    Integer h;

    public THI(int i,int w,int h) throws AWTException {
        this.robot = new Robot();
        this.i = i;
        this.w=w;
        this.h=h;
    }

    public void captureScreen(String fileName,int w,int h) throws IOException {
        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        screenRect.setSize(w, h);
        BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
        ImageIO.write(screenFullImage, "png", new File(fileName));
    }


    public  void main() {

                // 捕获10次作为示例
        try {
            this.captureScreen("./ev/screen_" + i++ + ".png",w,h);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void run() {
        main();
    }
}